<?php


namespace App\Transformers\Category;


use App\Models\Category\Category;
use League\Fractal\TransformerAbstract;

class CategoryTransformer extends TransformerAbstract
{
    public function transform(Category $data)
    {
        return [
            'id' => $data->id,
            'admin_id' => $data->admin_id ?? 0,
            'pid' => $data->pid ?? 0,
            'top_id' => $data->top_id ?? 0,
            'category_group_id' => $data->category_group_id ?? 0,
            'path' => $data->path ?? '',
            'name' => $data->name ?? '',
            'nickname' => $data->nickname ?? '',
            'image' => $data->image ?? '',
            'image_url' => $data->image ?? 'https://placeimg.com/640/480/any',
            'keywords' => $data->keywords ?? '',
            'description' => $data->description ?? '',
            'weigh' => $data->weigh ?? 0,
            'value' => $data->value ?? null,
            'level' => $data->level ?? 0,
            'status' => $data->status ?? 0,
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }
}
